import request from '@/utils/request'

export interface trademarkListModel {
  records: recordsModel[]
  total: number
  size: number
  current: number
  searchCount: boolean
  pages: number
}
export interface recordsModel {
  id: number
  tmName: string
  logoUrl: string
}

export interface formDataModel {
  id?: number
  logoUrl: string
  tmName: string
}

export default {
  // 获取品牌列表数据
  reqTrademark(page: number, pageSize: number) {
    return request.get<null, trademarkListModel>(`/admin/product/baseTrademark/${page}/${pageSize}`)
  },
  AETrademark(formData: formDataModel) {
    return request[formData.id ? 'put' : 'post']<null, null>(
      `/admin/product/baseTrademark/${formData.id ? 'update' : 'save'}`,
      formData
    )
  },
  deleteTrademark(id: number) {
    return request.delete(`/admin/product/baseTrademark/remove/${id}`)
  },
  // 获取用户列表
  reqUserList(current: number, pageSize: number, username: string) {
    return request.get<null, userListModel>(`/admin/acl/user/${current}/${pageSize}?username=${username}`)
  },
  // 删除用户列表
  deleteUser(id: string) {
    return request.delete(`/admin/acl/user/remove/${id}`)
  },
  AEUser(forData: userItemsModel) {
    return request[forData.id ? 'put' : 'post'](`/admin/acl/user/${forData.id ? 'update' : 'save'}`, forData)
  },
  reqUserRight(id: string) {
    return request.get<null, userRightModel>(`/admin/acl/user/toAssign/${id}`)
  },
  saveUser(userId: string, selectId: string[]) {
    return request.post(`/admin/acl/user/doAssign?userId=${userId}&roleId=${selectId}`)
  },
  reqRoleList(current: number, pageSize: number, roleName: string) {
    return request.get<null, { total: number; items: assignRolesModel[] }>(
      `/admin/acl/role/${current}/${pageSize}?roleName=${roleName}`
    )
  },
  // 删除角色列表
  deleteRole(id: string) {
    return request.delete(`/admin/acl/role/remove/${id}`)
  },
  saveRoleName(role: assignRolesModel) {
    return request.put('/admin/acl/role/update', role)
  },
  addRole(roleName: string) {
    return request.post('/admin/acl/role/save', { roleName })
  },
  reqTreeList(id:number){
    return request.get<null,{children:[]}>(`/admin/acl/permission/toAssign/${id}`)
  },
  saveAssign(roleId:string,permissionId:string[]){
    return request.post(`/admin/acl/permission/doAssign?roleId=${roleId}&permissionId=${permissionId}`)
  }
}

export interface userRightModel {
  assignRoles: assignRolesModel[]
  allRolesList: assignRolesModel[]
}
export interface assignRolesModel {
  id: string
  gmtCreate: string
  gmtModified: string
  deleted: boolean
  roleName: string
  remark: null
  isIpt?: boolean
}
export interface userListModel {
  total: number
  items: userItemsModel[]
}
export interface userItemsModel {
  id?: string
  gmtCreate?: string
  gmtModified?: string
  deleted?: boolean
  username: string
  password?: string
  nickName: string
  salt?: null
  token?: null
  roleName?: string
}
